#coding:utf8
'''
Created on 2012-11-29

@author: daizhaolin
'''

from flask import Flask, flash, make_response, redirect, request, render_template, url_for 
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bootstrap import Bootstrap

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
db = SQLAlchemy(app)
Bootstrap(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    mobile = db.Column(db.String(120), unique=True)

    def __init__(self, username, mobile):
        self.username = username
        self.mobile = mobile

    def __repr__(self):
        return self

@app.route('/', methods=["GET", "POST"])
def index():
    if request.cookies.get('text') == '1988':
        if request.method == "POST" and "name" in request.form and "mobile" in request.form:
            if len(request.form['name'].strip()) > 0 and len(request.form['mobile'].strip()) > 0:
                flash('True')
                return redirect(url_for('index'))
        return render_template('index.html')
    if request.method == "POST" and "text" in request.form and request.form['text'] == '依安':
        resp = make_response(redirect(url_for('index')))
        resp.set_cookie('text', '1988')
        return resp
    return render_template('men.html')

if __name__ == '__main__':
    app.run()
